<!-- S search -->
<app-search-bar
  [submitLoading]="tableForms.tableLoading"
  [searchOptions]="searchOptions"
  labelFlex="80px"
  (onSearch)="queryResetData($event)"
  (onReset)="queryResetData($event)"
>
</app-search-bar>
<!-- E search -->

<nz-card class="m-t-2">
  <div class="opera-wrap">
    <button
      *ngIf="permission.userPermission.has('promotionshare:gameManage:add')"
      nz-button
      nzType="primary"
      routerLink="/promotionshare/divide-game-edit"
      [queryParams]="{type: 0}">
      新增
    </button>
  </div>

  <!-- Table -->
  <div class="pagination-wrap-position table-wrap">
    <nz-table
      #basicTable
      nzOuterBordered
      nzSize="small"
      nzShowSizeChanger
      nzShowQuickJumper
      [nzScroll]="{ x: '1100px' }"
      [nzFrontPagination]="false"
      [nzLoadingDelay]="100"
      [nzLoading]="tableForms.tableLoading"
      [nzData]="tableData"
      [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
      [nzTotal]="tableForms.total"
      [nzPageIndex]="tableForms.page"
      [nzPageSize]="tableForms.pageSize"
      [nzShowTotal]="totalTemplate"
      (nzPageIndexChange)="onPageIndexChange($event)"
      (nzPageSizeChange)="onPageSizeChange($event)"
    >
      <thead>
        <tr>
          <th nzAlign="center" nzWidth="100px">排序</th>
          <th nzAlign="center" nzWidth="100px">ID</th>
          <th nzAlign="center" nzWidth="150px">开发者</th>
          <th nzAlign="center" nzWidth="150px">名称</th>
          <th nzAlign="center" nzWidth="100px">图标</th>
          <th nzAlign="center" nzWidth="100px">角标</th>
          <th nzAlign="center" nzWidth="150px">分成方式</th>
          <th nzAlign="center" nzWidth="120px">安装方式</th>
          <th nzAlign="center" nzWidth="120px">用户</th>
          <th nzAlign="center" nzWidth="120px">推广渠道</th>
          <th nzAlign="center" nzWidth="180px">分类</th>
          <th nzAlign="center" nzWidth="120px">是否启用</th>
          <th nzAlign="center" nzWidth="120px">新游推荐</th>
          <th nzAlign="center" nzWidth="130px">审核状态</th>
          <th nzAlign="center" nzWidth="300px" nzRight>操作</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let data of basicTable.data; let index = index;">
          <!-- 排序 -->
          <td nzAlign="center">{{ tableForms.pageSize * (tableForms.page - 1) + index + 1 }}</td>
          <!-- ID -->
          <td nzAlign="center">{{ data.id }}</td>
          <!-- 开发者 -->
          <td nzAlign="center">{{ data.developerName || '-' }}</td>
          <!-- 名称 -->
          <td nzAlign="center">{{ data.name || '-' }}</td>
          <!-- 图标 -->
          <td nzAlign="center">
            <img
              nz-image
              width="45px"
              height="45px"
              [nzSrc]="data.icon"
              [nzFallback]="defalutImg"
              alt=""
            />
          </td>
          <!-- 角标 -->
          <td nzAlign="center">
            <img
              nz-image
              width="45px"
              height="45px"
              [nzSrc]="data.cornerMarker"
              [nzFallback]="defalutImg"
              alt=""
            />
          </td>
          <!-- 分成方式 -->
          <td nzAlign="center">
            {{ data.sharingMode | sharingStatus }}
            <ng-container *ngIf="[1,2].includes(data.sharingMode);else templateSharing">
              <span *ngIf="data.commission || data.commission == 0">{{ data.commission }}元</span>
            </ng-container>
            <ng-template #templateSharing>
              {{ data.commission }}%
            </ng-template>
          </td>
          <!-- 安装方式 -->
          <td nzAlign="center">{{ data.installMode | installStatus }}</td>
          <!-- 用户 -->
          <td nzAlign="center">
            <span *ngIf="!data.userType && data.userType != 0">-</span>
            <nz-tag *ngIf="data.userType == 0">通用</nz-tag>
            <nz-tag [nzColor]="'#2db7f5'" *ngIf="data.userType == 2">B端</nz-tag>
            <nz-tag [nzColor]="'#87d068'" *ngIf="data.userType == 1">C端</nz-tag>
          </td>
          <!-- 推广渠道 -->
          <td nzAlign="center">{{ data.promotionChannels | promotionStatus }}</td>
          <!-- 分类 -->
          <td nzAlign="center">{{ data.typeName || '-' }}</td>
          <!-- 是否启用 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.state == 0 ? '#008000' : '#f00000'}">
              {{ data.state == 0 ? '是' : '否' }}
            </span>
          </td>
          <!-- 新游推荐 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.isRecommend == 0 ? '#008000' : '#f00000'}">
              {{ data.isRecommend === 0 ? '是' : (data.isRecommend === 1 ? '否' : '-') }}
            </span>
          </td>
          <!-- 审核状态 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.auditStatus | divideAppStatus: 'color'}">
              {{ data.auditStatus | divideAppStatus: 'label' }}
            </span>
          </td>
          <td nzAlign="center" nzRight>
            <button
              *ngIf="permission.userPermission.has('promotionshare:gameManage:move')"
              nz-button
              nzType="link"
              nzSize="small"
              [disabled]="tableForms.page == 1 && index == 0"
              (click)="sortTable(1, data.id)"
            >上移</button>

            <button
              *ngIf="permission.userPermission.has('promotionshare:gameManage:move')"
              nz-button
              nzType="link"
              nzSize="small"
              [disabled]="disabledMoveBtn(index)"
              (click)="sortTable(2, data.id)"
            >下移</button>

            <button
              *ngIf="data.status != 3 && permission.userPermission.has('promotionshare:gameManage:edit')"
              nz-button
              nzType="link"
              nzSize="small"
              routerLink="/promotionshare/divide-game-edit"
              [queryParams]="{type: 1, id: data.id}">
              编辑
            </button>

            <button
              nz-button
              nzType="link"
              nzSize="small"
              routerLink="/promotionshare/divide-game-details"
              [queryParams]="{id: data.id}">
              查看
            </button>

            <button
              *ngIf="data.auditStatus === 1"
              nz-button
              nzType="link"
              nzSize="small"
              (click)="showExamineModal(data)">
              审核
            </button>

            <a
              *ngIf="data.status != 3 && permission.userPermission.has('promotionshare:gameManage:delete')"
              nz-button
              nzType="link"
              nzSize="small"
              nzDanger
              nz-popconfirm
              nzPopconfirmTitle="确认删除吗?"
              (nzOnConfirm)="deleteConfirm(data.id)">
              删除
            </a>

            <a
              *ngIf="data.status != 3 && permission.userPermission.has('promotionshare:gameManage:disable')"
              nz-button
              nzType="link"
              nzSize="small"
              nzDanger
              [ngStyle]="{'color': data.state == 0 ? '#FF4D4F' : '#67C23A'}"
              nz-popconfirm
              [nzPopconfirmTitle]="'确认' + (data.state == 0 ? '禁用' : '启用') + '?'"
              (nzOnConfirm)="onOffItem(data)">
              {{ data.state == 0 ? '禁用' : '启用' }}
            </a>
          </td>
        </tr>
      </tbody>
    </nz-table>

    <!-- 分页template -->
    <ng-template #totalTemplate let-total>共有 {{ tableForms.total }} 条</ng-template>
  </div>
</nz-card>

<!-- S 审核 Modal -->
<nz-modal
  nzClassName="custom-model-wrap"
  [nzFooter]="null"
  [(nzVisible)]="isExamineVisible"
  [nzTitle]="'审核'"
  (nzOnCancel)="isExamineVisible = false">

  <div *nzModalContent>
    <div class="custom-model-body">
      <nz-textarea-count [nzMaxCharacterCount]="150">
        <textarea
          rows="4"
          nz-input
          maxlength="150"
          placeholder="请输入审核意见"
          [(ngModel)]="auditOpinion"
        ></textarea>
      </nz-textarea-count>
    </div>

    <div class="custom-model-foot">
      <div class="custom-foot-cont">
        <button nz-button nzType="primary" (click)="subExamine(2)">审核通过</button>
        <button nz-button nzType="primary" nzDanger (click)="subExamine(3)">审核不通过</button>
      </div>
    </div>
  </div>
</nz-modal>
<!-- E 审核 Modal -->